//import 'package:amap_base/amap_base.dart';

import 'dart:async';
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hotwork/HomePage.dart';
import 'package:flutter_hotwork/baobiao/TongJiBaoBiao.dart';
import 'package:flutter_hotwork/bean/BaseBean.dart';
import 'package:flutter_hotwork/bean/HotUserMessageBean.dart';
import 'package:flutter_hotwork/homepage/BaseTitleBar.dart';
import 'package:flutter_hotwork/homepage/BaseViewBar.dart';
import 'package:flutter_hotwork/utils/DioUtils.dart';
import 'package:fluttertoast/fluttertoast.dart';
// import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';

import '../../LoadingDialog.dart';
import '../../Myapplication.dart';
import '../../Toast.dart';

class hotusermessagecenterPage extends StatefulWidget {
  @override
  messagecenterState createState() => new messagecenterState();
}
HotUserMessageBean messagelist;
bool hasdata = false;
class messagecenterState extends State<hotusermessagecenterPage> {

  @override
  void initState() {
    super.initState();
    DioUtils.createInstance();
  }

  @override
  void dispose() {
//    _amapLocation.stopLocate();
    super.dispose();
  }
  void getHotUserInfo() async {
    try {
      Response response = await DioUtils.dio.get(DioUtils.API_PREFIX+"/NoticeApproval/noticeApprovalList?auditStatus=4");

      Map respMap = json.decode(response.data);
      messagelist  = HotUserMessageBean.fromJson(respMap);
      if (messagelist.code == 200) {
          hasdata = true;
          setState(() {
          });



        // rebuild();
      } else {
         LocalToast.toast(context,msg: messagelist.message);
      }
      print('响应数据：' + response.toString());
    } catch (e) {
      //  LocalToast.toast(context,msg: "网络错误");
      print('请求出错：' + e.toString());
    }
  }

  void updatefuheyuce(String id) async {
    showDialog(
        context: context,
        builder: (context) {
          return new LoadingDialog();
        });
    // Navigator.pop(context);
    try {

      var reqeuest =Map<Object,Object>();
      reqeuest["confirmBy"] = MyApplication.loginuserinfo.userInfo.realname;
      reqeuest["id"] = id;
      Response response;
      response = await DioUtils.dio.put(DioUtils.API_PREFIX+"/NoticeApproval/confirmNoticeApproval", data: json.encode(reqeuest));
      Map respMap = json.decode(response.data);
      basebean bean  = basebean.fromJson(respMap);
      Navigator.pop(context);
      if (bean.code == 0) {
        getHotUserInfo();
      } else {
        LocalToast.toast(context,msg: bean.message);
      }
    } catch (e) {
      Navigator.pop(context);
      LocalToast.toast(context,msg: "提交失败");
    }
  }

  TabController _tabController;

  @override
  Widget build(BuildContext context) {
    if(!hasdata){
      getHotUserInfo();
    }
    ScrollController controller = ScrollController();

    return Scaffold(
      appBar: new BaseViewBar(
          childView: new BaseTitleBar(
            "消息中心",
            leftIcon: 'images/fanhui.png',
            rightIcon:  '',
            rightClick: () {
            },
            leftClick: () {
              print("点击了左边干嘛啊。。。哦");
              Navigator.of(context).pop();
            },
          ),
          preferredSize: Size.fromHeight(50.0)),

      body:

      hasdata?
      Container(
        child:
        Column(
          children: [
            Expanded(
              child:
              genContentList(
                  messagelist.result,context, controller
              ),
            ),
          ],
        ),
      ):Container(

        child:
        Column(
          mainAxisAlignment:MainAxisAlignment.center,
          crossAxisAlignment:CrossAxisAlignment.center,
          children: [
            Row(
              mainAxisAlignment:MainAxisAlignment.center,
              crossAxisAlignment:CrossAxisAlignment.center,
              children: [
                Text("暂无消息"),
              ],

            ),


          ],
        )
        ,
      ),
    );
  }


  genContentList(List<Result> data, BuildContext context, controller){
    double rpx = MediaQuery.of(context).size.width / 750;
    return ListView.builder(
        shrinkWrap: true,
        controller: controller,
        itemCount: data.length,
        itemBuilder:(BuildContext context, int index){
          return Container(

            decoration: BoxDecoration(
              color: Colors.white,
              boxShadow: <BoxShadow>[//设置阴影
                new BoxShadow(
                  color: Colors.grey,//阴影颜色
                  blurRadius:1.0,//阴影大小
                ),
              ],
            ),

            margin: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:10),
            // height: 260 * rpx,
            child: Column(
              children: <Widget>[
                Container(
                  height: 10,
                ),
                Container(
                  padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:0),
                  child: Row(
                    crossAxisAlignment:CrossAxisAlignment.center,
                    children: [
                      Container(
                        width: 10,
                      ),
                      Text(data[index].fullName.toString(),style: new TextStyle(color: Color(0xFF333333),
                        fontSize: 14.0,
                      ),
                        maxLines: 3,
                        softWrap: true,
                      ),
                      Flexible(fit: FlexFit.tight, child: SizedBox()),

                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:0),
                  margin: EdgeInsets.only(left: 0,top: 10,right: 0,bottom: 10),
                  child: Row(
                    children: [
                      // Image(height:20,width: 20,image: AssetImage('images/mingcheng.png')),
                      Container(
                        width: 10,
                      ),
                        Text("余额:"+data[index].balance.toString(),style: new TextStyle(color: Color(0xFF666666),
                          fontSize: 12.0,
                        ),
                          maxLines: 10,
                          softWrap: true,
                        ),
                      Container(
                        width: 10,
                      ),
                      Text("      结算量:"+data[index].settlementCount.toString()+"(t)",style: new TextStyle(color: Color(0xFF666666),
                        fontSize: 12.0,
                      ),
                        maxLines: 3,
                        softWrap: true,),

                    ],
                  ),
                ),


                Container(
                  padding: EdgeInsets.only(left: 10,top: 0,right: 10,bottom:10),
                  child: Row(
                    crossAxisAlignment:CrossAxisAlignment.center,
                    children: [
                      InkWell(
                        onTap: (){
                          Navigator.push(context, MaterialPageRoute(builder: (context) {
                            return new tongjibaobiaoPage();
                          }));
                        },
                        child:
                        Container(
                            width: 50,
                            height: 20,
                            margin: EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                            padding:  EdgeInsets.only(left: 2, right: 2, top:0, bottom: 0),
                            decoration: BoxDecoration(
                              // border: new Border.all(color: Colors.blue, width: 0.5), // 边色与边宽度
                              color: Colors.blue, // 底色
                              borderRadius: new BorderRadius.circular((5.0)), // 圆角度
                            ),
                            child:
                            Row(
                              mainAxisAlignment:MainAxisAlignment.center,
                              children: [
                                Text("查看详情",
                                  style: TextStyle(color: Colors.white,fontSize: 10),
                                )

                              ],
                            )
                        ),
                      ),
                      Container(
                        width: 40,
                      ),
                      data[index].isConfirm!=1?InkWell(
                        onTap: (){
                          updatefuheyuce(data[index].id);
                        },
                        child:
                        Container(
                            width: 50,
                            height: 20,
                            margin: EdgeInsets.only(left: 10, right: 0, top:0, bottom: 0),
                            padding:  EdgeInsets.only(left: 2, right: 2, top:0, bottom: 0),
                            decoration: BoxDecoration(
                              // border: new Border.all(color: Colors.blue, width: 0.5), // 边色与边宽度
                              color: Colors.blue, // 底色
                              borderRadius: new BorderRadius.circular((5.0)), // 圆角度
                            ),
                            child:
                            Row(
                              mainAxisAlignment:MainAxisAlignment.center,
                              children: [
                                Text("已读",
                                  style: TextStyle(color: Colors.white,fontSize: 10),
                                )

                              ],
                            )
                        ),
                      ):Container(),
                    ],
                  ),
                ),
              ],
            ),
          );
        }
    );
  }

}






















